document.getElementById('workbench-link').addEventListener('click', function (e) {
    e.preventDefault();

    const kbList = document.getElementById('kb-list');
    const noData = document.getElementById('no-data');
    const loading = document.getElementById('loading');

    // 显示加载状态
    kbList.style.display = 'none';
    noData.style.display = 'none';
    loading.style.display = 'block';

    fetch(KNOWBASE_KNOWBASELIST_URI)
        .then(response => response.json())
        .then(data => {
            loading.style.display = 'none';

            if (data.statusCode === 200 && data.data && data.data.length > 0) {
                // 清空旧内容
                kbList.innerHTML = '';

                // 使用 DOM 操作创建元素（非字符串拼接）
                data.data.forEach(kb => {
                    const card = document.createElement('div');
                    card.className = 'kb-card';

                    const h3 = document.createElement('h3');
                    h3.textContent = kb.know_base_name;

                    const p1 = document.createElement('p');
                    p1.innerHTML = `<strong>创建时间:</strong> ${new Date(kb.create_date).toLocaleDateString()}`;

                    const p2 = document.createElement('p');
                    //p2.innerHTML = `<strong>ID:</strong> ${kb.know_base_id.substring(0, 8)}...`;

                    card.appendChild(h3);
                    card.appendChild(p1);
                    //card.appendChild(p2);
                    kbList.appendChild(card);
                });

                kbList.style.display = 'flex'; // 显示图标列表
            } else {
                noData.style.display = 'block'; // 显示“无数据”
            }
        })
        .catch(error => {
            loading.style.display = 'none';
            console.error('加载失败:', error);
            alert('加载知识库失败，请稍后重试。');
        });
});